﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using System.Threading.Tasks;
using MvcCoffeeShop.DataTransferObjects;
using System.Data.Entity;
using System.Data.EntityClient;
using System.Data.SqlClient;
using System.Globalization;
using System.Data.Common;
using System.Configuration;
using DAL;

namespace MvcCoffeeShop.DataAccess
{
    public class MvcCoffeeShopDA
    {
        //http://www.codeproject.com/Articles/19154/Understanding-LINQ-C
        MvcCoffeeShopEntities context = new MvcCoffeeShopEntities();

        public List<ProductDTO> GetProducts()
        {
             
            var oProducts = (context.Products.Select(x =>
                             new ProductDTO
                             {
                                 ProductID = x.ProductID,
                                 ProductName = x.ProductName,
                                 ProductDesc = x.ProductDesc,
                                 SupplierID = x.SupplierID,
                                 Quantity = x.Quantity,
                                 UnitPrice = (double)x.UnitPrice,
                                 PicturePath = x.PicturePath
                             })).ToList();

            return oProducts;

        }

        public ProductDTO GetProduct(int ProductID)
        {
            var oProduct = (context.Products.Where(x => x.ProductID == ProductID).Select(x => 
                            new ProductDTO { ProductID = x.ProductID,
                                             ProductName = x.ProductName, 
                                             ProductDesc = x.ProductDesc, 
                                             SupplierID = x.SupplierID, 
                                             Quantity = x.Quantity, 
                                             UnitPrice = (double)x.UnitPrice, 
                                             PicturePath=x.PicturePath})).FirstOrDefault();

            return oProduct;
        }
    }
}
